﻿using CatUtils.Utils.Currency.IoUtils;
using CatUtils.Utils.SpecialUtils.Html;
using System;
using System.Collections.Generic;

namespace SinaImgUpload.SainTool.LocalTool
{
    internal class ClearListRepeat
    {
        /// <summary>
        /// 批量清理失效Sain链接
        /// </summary>
        /// <param name="FloderPath"></param>
        internal void ClearXmlWithFloder(string FloderPath)
        {
            List<string> FoloderList = FloderNameHelper.GetFullFileNameList(FloderPath, "*.lst");
            foreach (string line in FoloderList)
            {
                Console.WriteLine(line);
                ClearSingleXml(line);
            }
        }

        /// <summary>
        ///  清理单个重复内容
        /// </summary>
        /// <param name="XmlFile"></param>
        public void ClearSingleXml(string XmlFile)
        {
            List<string> InfoList = HtmlHelper.GetHtmlValueList(FileHelper.ReadAllText(XmlFile), "//bed");
            List<string> FileNameList = new List<string>();
            string NewFilePath = FileNameHelper.CreateFileNameWithChildFloder(XmlFile, "去重复");
            foreach (String Line in InfoList)
            {
                string FileUrl = HtmlHelper.GetFirstText(Line, "//original");
                if (FileNameList.Contains(FileUrl))
                    continue;
                FileNameList.Add(FileUrl);
                FileHelper.AppendText(NewFilePath, Line);
            }
        }
    }
}